package com.learn.model;

import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import lombok.experimental.Accessors;

import javax.persistence.*;
import java.io.Serializable;
import java.time.LocalDateTime;

/**
 * 实体类必须实现序列化，否则传输过程中会有问题
 */
@Getter
@Setter
@NoArgsConstructor
@Accessors(chain = true)
@Entity
@Table(name = "notice")
public class Notice implements Serializable {
    @Id
    @Column(name = "id")
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Integer id;
    
    private String title;
    
    @Lob
    @Column(columnDefinition = "TEXT")
    private String content;
    
    @Enumerated(EnumType.STRING)
    private NoticeType noticeType;
    
    private LocalDateTime entryDate;
    
    // 微服务中每个服务都可以有自己的数据库，此字段可查看库名
    private String dbSource;
    
    @Getter
    @AllArgsConstructor
    public enum NoticeType {
        GENERAL(1, "普通公告"),
        IMPORTANT(2, "重要公告"),
        URGENT(2, "紧急公告");
        
        private final Integer code;
        private final String name;
    }
}
